package com.pepsico.introjava.labs;

import com.pepsico.introjava.exceptions.InvalidParameterException;
import com.pepsico.introjava.exceptions.InvalidRangeException;

public class Employee extends TaxEntity
{
	
	public static final float FICA_TAX_RATE = .0765f;
	private float salary;
	private float ytdSalary;
	private float ytdTax;
	
	public Employee (Employee other)	// copy constructor
	{
		this (other.getName(), other.getSalary());
		ytdSalary = other.getYtdSalary();
		ytdTax = other.getYtdTax();
	}
	public Employee ()
	{
		this ("Fred");	// Fred is the default name
	}
	
	public Employee (String name)
	{
		this (name, 50); 	// 50 is the default salary
	}
	public Employee(String name, float salary) 
	{
		super(name);
		setSalary (salary);
	}
	
	@Override
	protected String getNameValidationExpression()
	{
		return "^[\\w\\s]{2,30}$";
	}
		
	public float getSalary()
	{
		return salary;
	}
	public void setSalary(String value)
	{
		setSalary(Float.parseFloat(value));
	}
	public void setSalary(float value) throws InvalidRangeException
	{
		if (value > 20 && value < 10000)
			salary = value;
		else
			throw new InvalidRangeException("Salary", 20, 10000, value);
	}
	
	
	public float getYtdSalary()
	{
		return ytdSalary;
	}
	public float getYtdTax()
	{
		return ytdTax;
	}
	
	
	/*****
	 * Pay this employee the amount, increasing ytd values.
	 * more details here, including <b>html</b>
	 * @param amount the amount paid
	 * @return the net pay (amount minus taxes)
	 */
	public float pay (float amount)
	{
		float tax = amount * FICA_TAX_RATE;
		ytdTax += tax;
		this.ytdSalary += amount;
		return amount - tax;
	}
	
	/***
	 * Calls pay(salary)
	 * @return
	 */
	public float pay()
	{
		return pay(salary);
	}
	
	@Override
	public String toString()
	{
		return super.toString() + " salary: " + getSalary() + " YTD Pay:" + getYtdSalary();
	}	
	
	
}
